﻿
using Repositories.Interfaces;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System;
namespace Repositories.Implementations
{
  public class CategoryRepository : BaseRepository<Category>, ICategoryRepository
  {
      public CategoryRepository()
		  : base()
    {
    }
    /// <summary>
    /// Gets the name of the entity set.
    /// </summary>
    /// <value>The name of the entity set.</value>
    protected override string EntitySetName
    {
      get
      {
          return "ASE_DatabaseEntities.Category";
      }      
    }

    public void Refresh()
    {
        ASEDbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, ASEDbContext.Category);
    }

    private ICategoryRepository _CategoryRepository;

    /// <summary>
    /// Gets the Category repository.
    /// </summary>
    /// <value>The Category repository.</value>
    public ICategoryRepository CategoryRep
    {
        get
        {
            if (_CategoryRepository == null)
            {
                _CategoryRepository = DIHelper.Resolve<ICategoryRepository>();
            }
            return _CategoryRepository;
        }
    }

 


    /// <summary>
    /// Creates the Category.
    /// </summary>
    /// <param name="item">The item.</param>
    public void CreateCategory(Category item)
    {
        CategoryRep.Insert(item);
    }

    /// <summary>
    /// Queries the Category.
    /// </summary>
    /// <param name="predicate">The predicate.</param>
    /// <returns>Query results.</returns>
    public IQueryable<Category> QueryCategory(Expression<Func<Category, bool>> predicate)
    {
        return CategoryRep.GetQuery(predicate);
    }

    /// <summary>
    /// Finds the by ID.
    /// </summary>
    /// <param name="id">The id.</param>
    /// <returns>The Category with input ID.</returns>
    public Category FindById(int id)
    {
        IQueryable<Category> returnValue = CategoryRep.GetQuery(itm => itm.Id == id);
        if (returnValue.Count() == 0)
            return null;
        return returnValue.FirstOrDefault();
    }

    /// <summary>
    /// Gets all Category.
    /// </summary>
    /// <returns>all Category.</returns>
    public List<Category> GetAllCategory()
    {
        IQueryable<Category> returnValue = CategoryRep.GetQuery();
        if (returnValue.Count() == 0)
            return null;
        return returnValue.ToList();
    }


    public Category GetCategoryByOrder(int order)
    {
        IQueryable<Category> returnValue = CategoryRep.GetQuery(itm => itm.Order == order);
        if (returnValue.Count() == 0)
            return null;
        return returnValue.FirstOrDefault();
    }

    /// <summary>
    /// Get All Category For DropDownList
    /// </summary>
    public List<Category> GetAllCategorysForDropDownList()
    {
        List<Category> listCategory = new List<Category>();
      
        return listCategory;
    }

    /// <summary>
    /// Get All Category For DropDownList
    /// </summary>
    public List<Category> GetAllCategoriesForDropDownList()
    {
        List<Category> listCategory = new List<Category>();
      
        return listCategory;
    }

    /// <summary>
    /// Edits the Category.
    /// </summary>
    /// <param name="item">The item.</param>
    public void EditCategory(Category item)
    {
        CategoryRep.Update(item);
    }


    /// <summary>
    /// Deletes the Category.
    /// </summary>
    /// <param name="item">The item.</param>
    public void DeleteCategory(Category item)
    {
        CategoryRep.Delete(item);
    }

    
    /// <summary>
    /// Deattaches the specified category.
    /// </summary>
    /// <param name="category">The category.</param>
    public void Deattach(Category category)
    {
      
    }

    /// <summary>
    /// Deattaches the specified Category.
    /// </summary>
    /// <param name="solicitation">The Category.</param>
    public void DeattachTo(Category combo)
    {
        CategoryRep.DeattachTo(combo);
    }

    /// <summary>
    /// Applies the changes to database.
    /// </summary>
    public void ApplyTheChanges()
    {
        CategoryRep.UnitOfWork.SaveChanges();
    }

    /// <summary>
    /// Accepts all changes.
    /// </summary>
    public void AcceptAllChanges()
    {
        CategoryRep.UnitOfWork.AcceptAllChanges();
    }


  }
}
